<template>
    <div
        class="calendar-item-container"
        :class="[
            {
                'is-current': col.isCurrent,
                'is-holidays': col.isHolidays,
                'is-week': col.isWeek,
                'is-selected': col.date === props.time,
                'is-current-month': isCurrentMonth(col.date),
            },
        ]"
        @click="changeTargetDate(col)"
    >
        <div class="holidays-text" v-if="col.isHolidays">休</div>
        <span class="calendar-title">{{ col.title }}</span>
        <span class="calendar-lunar">{{ col.lunarsChina }}</span>
    </div>
</template>

<script lang="ts" setup>
import { PropType } from 'vue';
import DateClass from './DateClass';
import { dateBase } from './Calendar';
const props = defineProps({
    col: {
        type: Object as PropType<dateBase>,
        default: () => {
            return {};
        },
    },
    time: {
        type: String,
        default: '',
    },
});

function isCurrentMonth(time: string) {
    const months = time.split('-')[1];
    return DateClass.getCurrent()[1] === Number(months);
}

const emit = defineEmits(['changeTargetDate']);
function changeTargetDate(time: dateBase) {
    emit('changeTargetDate', time);
}
</script>

<style scoped lang="less">
.calendar-item-container {
    position: relative;

    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    box-sizing: border-box;
    border-radius: 6px;
    border: 2px solid #ffffff;

    .calendar-title {
        font-size: 1.2rem;
        color: #999999;
    }
    .calendar-lunar {
        margin-top: 6px;

        font-size: 0.85rem;
        color: #bcbcbc;
    }
    transition: all 0.2s;
}
.calendar-item-container:hover {
    cursor: pointer;
    border: 2px solid #409eff;
}
.is-holidays {
    .holidays-text {
        position: absolute;
        top: 6px;
        left: 14px;
        font-size: 0.85rem;
        color: #ffa2a2;
    }
    .calendar-title {
        color: #ffa2a2;
    }
    background-color: #feeeef;
}
.is-selected {
    border: 2px solid #409eff;
}
.is-holidays.is-selected {
    border: 2px solid #ffa2a2;
}
.is-selected.is-current-month {
    border: 2px solid #409eff;
}
.is-holidays.is-selected.is-current-month {
    border: 2px solid #f62b2b;
}
.is-week {
    .calendar-title {
        color: #ffa2a2;
    }
}
.calendar-item-container.is-current {
    .calendar-title {
        color: #333333;
    }
    .calendar-lunar {
        color: #666666;
    }
}
.calendar-item-container.is-current.is-holidays {
    .holidays-text {
        position: absolute;
        top: 6px;
        left: 14px;
        font-size: 0.85rem;
        color: #f62b2b;
    }
    background-color: #fbe3e4;
}
.calendar-item-container.is-current.is-holidays,
.calendar-item-container.is-current.is-week {
    .calendar-title {
        color: #f62b2b;
    }
}
.calendar-item-container.is-current.is-holidays {
    .holidays-text {
        position: absolute;
        top: 6px;
        left: 14px;
        font-size: 0.85rem;
        color: #fb4949;
    }
    .calendar-title {
        color: #fb6e6e;
    }
    background-color: #ffe4e7;
}
.calendar-item-container.is-holidays:hover {
    border: 2px solid #f62b2b;
}
</style>
